﻿using FarPoint.Web.Chart;
using FarPoint.Web.Chart.Design;
using FarPoint.Web.Spread.Chart;
using FarPoint.Web.Spread.Model;
using System;

namespace ControlExplorer.samples.Charting
{
  public partial class Overview : SpreadDemoPage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        this.FpSpread1.Sheets[0].AddChart(new CellRange(0, 0, 5, 6), typeof(ClusteredBarSeries), 495, 305, 149, 122);
        FpSpread1.Sheets[0].Charts[0].RenderMapArea = true;
        FpSpread1.Sheets[0].Charts[0].AutoGenerateMapAreaToolTip = true;
        this.FpSpread1.UseClipboard = false;
      }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
      ChangeChartType(DropDownList1.Text);
    }

    private void ChangeChartType(string type)
    {
      ChartModel chrtModel;
      ChartViewType viewType;

      ChartType chartType = (ChartType)Enum.Parse(typeof(ChartType), type);
      InsertChart.GetChartModel(chartType, out chrtModel, out viewType);

      SpreadChart spreadChart = this.FpSpread1.ActiveSheetView.Charts[0];
      spreadChart.ChangeChartType(chrtModel);
      spreadChart.ViewType = viewType;
      //spreadChart.RenderMapArea = true;
      //this.CheckBox1.Checked = viewType == ChartViewType.View3D;
      this.FpSpread1.ActiveSheetView.ActiveChart = null;
    }

    protected void ddlChartCat_SelectedIndexChanged(object sender, EventArgs e)
    {
      ChartCategroies.XPath = "//category[@text='" + ddlChartCat.Text + "']/item";
      ChartCategroies.DataBind();
      string chartType = "";
      switch (ddlChartCat.Text)
      {
        case "Column": chartType = "ClusteredColumnChart";
          break;
        case "Line": chartType = "LineIn2DChart";
          break;
        case "Pie": chartType = "PieIn2DChart";
          break;
        case "Bar": chartType = "ClusteredBarChart";
          break;
        case "Area": chartType = "AreaIn2DChart";
          break;
        case "XY": chartType = "XYPointChart";
          break;
        case "Bubble": chartType = "XYBubbleIn2DChart";
          break;
        case "Stock": chartType = "HighLowCloseChart";
          break;
        case "XYZ": chartType = "XYZLineChart";
          break;
        case "Doughnut": chartType = "DoughnutChart";
          break;
        case "Radar": chartType = "RadarLineChart";
          break;
        case "Polar": chartType = "PolarLineChart";
          break;
        default: chartType = "ClusteredColumnChart";
          break;
      }
      ChangeChartType(chartType);
    }


    //protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    //{
    //  this.FpSpread1.ActiveSheetView.Charts[0].ViewType = this.CheckBox1.Checked ? ChartViewType.View3D : ChartViewType.View2D;
    //}
  }
}